package com.deer.wms.busine.tactic.web;

import com.deer.wms.busine.tactic.model.Wave.WaveTactic;
import com.deer.wms.busine.tactic.model.Wave.WaveTacticCriteria;
import com.deer.wms.busine.tactic.model.Wave.WaveTacticDto;
import com.deer.wms.busine.tactic.service.WaveTacticService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by ll on 2020/02/03.
*/
@RestController
@RequestMapping("/wave/tactics")
public class WaveTacticController {

    @Autowired
    private WaveTacticService waveTacticService;

    @PostMapping("/add")
    public Result add(@RequestBody WaveTactic waveTactic) {
        waveTacticService.save(waveTactic);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        waveTacticService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody WaveTactic waveTactic) {
        waveTacticService.updateById(waveTactic);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        WaveTactic waveTactic = waveTacticService.getById(id);
        return ResultGenerator.genSuccessResult(waveTactic);
    }

    @GetMapping
    public Result list(WaveTacticCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<WaveTacticDto> list = waveTacticService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
